package com.dayuanit.dy17.library.service.impl;

import com.dayuanit.dy17.library.entity.User;
import com.dayuanit.dy17.library.exception.BizException;
import com.dayuanit.dy17.library.mapper.UserMapper;
import com.dayuanit.dy17.library.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    public UserServiceImpl() {
        System.out.println("-------UserServiceImpl-------");
    }

    @Override
    public User login(String username, String password) {
        // 根据用户名查询用户
        User user = userMapper.getUserbyName(username);
        if (null == user) {
            throw new BizException("用户名不存在");
        }

        // 校验密码
        if (!user.getPassword().equals(password)) {
            throw new BizException("密码错误");
        }

        return user;
    }
}
